@extends('admin.layouts.base')

@section('content')
    <div class="row wrapper border-bottom white-bg page-heading">
        <div class="col-sm-4">
            <h2>{{trans('adminNavHeader.permission_manager')}}</h2>
            {!! Breadcrumbs::render(Route::currentRouteName()) !!}
        </div>
        @if(Auth::guard('admin')->user()->can('admin.permission.create'))
        <div class="col-sm-8">
            <div class="title-action">
                <a href="/admin/permission/{{$datas['cid']}}/create" class="btn btn-primary"><i class="fa fa-plus-circle"></i> 添加权限</a>
            </div>
        </div>
        @endif
    </div>
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>
                            @if($datas['cid']==0)
                                [菜单列表]
                                <a class="btn btn-primary btn-sm" href="{{url('admin/permission')}}"><i class="fa fa-home"></i> 顶级菜单</a>
                            @else
                                [{{$datas['curr']->display_name}}]
                                <a class="btn btn-primary btn-sm" href="{{url('admin/permission')}}"><i class="fa fa-reply"></i> 返回顶级菜单</a>
                            @endif
                        </h5>
                    </div>
                    @include('admin.partials.errors')
                    @include('admin.partials.success')
                    <div class="ibox-content">
                        <form action="{{url("admin/permission/listorder")}}" method="post">
                            {!! csrf_field() !!}
                            <input type="hidden" name="cid" value="{{$datas['cid']}}">
                        <table class="footable table table-stripped toggle-arrow-tiny tablet breakpoint footable-loaded" data-page-size="8">
                            <thead>
                            <tr>
                                <th class="footable-visible footable-first-column footable-sortable">排序</th>
                                <th class="footable-visible footable-first-column footable-sortable">ID</th>
                                <th class="footable-visible footable-sortable">权限规则<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-sortable">权限名称<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-sortable">权限描述<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-sortable">创建时间<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-sortable">更新时间<span class="footable-sort-indicator"></span></th>
                                <th class="footable-visible footable-last-column footable-sortable">操作<span class="footable-sort-indicator"></span></th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($datas['data'] as $data)
                            <tr id="role{{ $data->id }}" style="display: table-row;" class="footable-even">
                                <td class="footable-visible footable-first-column col-xs-1">
                                    <input type="text" name="listorders[{{$data->id}}]" value="{{$data->listorder}}" class="form-control" style="text-align: center;height: 23px;padding: 0 10px;">
                                </td>
                                <td class="footable-visible footable-first-column">{{$data->id}}</td>
                                <td class="footable-visible">{{$data->name}}</td>
                                <td class="footable-visible">{{$data->display_name}}</td>
                                <td class="footable-visible">{{$data->description}}</td>
                                <td class="footable-visible">{{$data->created_at}}</td>
                                <td class="footable-visible">{{$data->updated_at}}</td>
                                <td class="footable-visible footable-last-column">
                                    @if($datas['cid']==0)
                                        <a href="/admin/permission/{{$data->id}}" class="btn btn-xs btn-primary"><i class="fa fa-adn"></i>子级菜单</a>
                                        @if(Auth::guard('admin')->user()->can('admin.permission.edit'))
                                            <a href="{{url("admin/permission/$data->id/edit")}}" class="btn btn-success btn-xs" value=""><i class="fa fa-edit"></i> 编辑</a>
                                        @endif
                                        @if(Auth::guard('admin')->user()->can('admin.permission.destroy'))
                                            <button type="button" class="btn btn-danger btn-xs delete" value="{{$data->id}}"><i class="fa fa-trash"></i> 删除</button>
                                        @endif
                                    @else
                                        @if(Auth::guard('admin')->user()->can('admin.permission.edit'))
                                            <a href="{{url("admin/permission/$data->id/edit")}}" class="btn btn-success btn-xs" value=""><i class="fa fa-edit"></i> 编辑</a>
                                        @endif
                                        @if(Auth::guard('admin')->user()->can('admin.permission.destroy'))
                                            <button type="button" class="btn btn-danger btn-xs delete" value="{{$data->id}}"><i class="fa fa-trash"></i> 删除</button>
                                        @endif
                                    @endif
                                </td>
                            </tr>
                            @endforeach
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="8" class="footable-visible">
                                    <div class="col-sm-1" style="padding-left: 0;">
                                        <button class="btn btn-primary" type="submit">提交排序</button>
                                    </div>
                                    {!! $datas['data']->links() !!}
                                </td>
                            </tr>
                            </tfoot>
                        </table>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="modal-delete" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这个权限吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="deleteForm" method="POST" action="">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
@stop
@section('js')
    <script type="text/javascript">
        $('button.delete').bind('click',function () {
            var id = $(this).val();
            $('.deleteForm').attr('action','/admin/permission/' + id);
            $("#modal-delete").modal();
        })
    </script>
@endsection
